

import { getSongUrl} from '../hooks/song-url'

class Song {


    id:string;
    artists: string;
    name:string;
    album:string;
    duration:number;
    imgUrl:string;
    url:string;

    constructor({id,name,artists,album,url,imgUrl,duration}){

        
        this.id = id
        this.artists = artists
        this.name = name
        this.album = album
        this.duration = duration
        this.imgUrl = imgUrl
        this.url = url;

    }

}


 function createSong(songInfo){


 

    return new Song({//因为网易云API获取的数据属性名有区别,所以要做一下判断 
        id:songInfo.id,
        name:songInfo.name ,
        artists:songInfo.artists ?  songInfo.artists[0].name : songInfo.ar[0].name,
        album:songInfo.album ? songInfo.album.name : songInfo.al.name,
        duration:songInfo.duration ? songInfo.duration : songInfo.dt,
        imgUrl:songInfo.album ? songInfo.album.picUrl : songInfo.al.picUrl,
        url:getSongUrl(songInfo.id)
    })


}

export {createSong}